package com.xiaoyu.im.request.flow;

import com.xiaoyu.base.entity.ConversationEntity;
import com.xiaoyu.im.IMLog;
import com.xiaoyu.im.datamodel.AppMessage;
import com.xiaoyu.im.provider.ConversationManager;
import com.xiaoyu.im.request.MessageRequest;

public class BaseSuccessAction implements FlowAction {

    @Override
    public void exec(MessageRequest request) {
        onSuccess(request);
        logSuccessEvent(request);
    }

    protected void onSuccess(MessageRequest request) {

    }

    private void logSuccessEvent(MessageRequest request) {
        final AppMessage successMessage = request.getSuccessMessage();
        if (successMessage == null) {
            return;
        }

        final String chatId = successMessage.chatToken.getChatId();
        ConversationEntity conversation = ConversationManager.getInstance().fetchConversation(chatId);
        if (conversation == null) {
            return;
        }
        IMLog.logImStreamForSend(successMessage, conversation);
    }
}
